package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.Employee;
import com.atguigu.springcloud.service.EmployeeClientService;
import com.atguigu.springcloud.service.OrderInfoService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * Created by luojie on 2018/9/7.
 */
@RestController("orderInfoController")
@Api(tags = "订单接口")
@CrossOrigin //跨域访问 swagger 要使用到
public class OrderInfoController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private EmployeeClientService employeeClientService;

    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation("根据id查找员工")
    @GetMapping("/employee/get/{id}")
    public Employee get(@PathVariable("id") String id){

        return employeeClientService.findById(id);
    }

    @ApiOperation("保存员工和订单（测试分布式事务）")
    @GetMapping("/saveEmployeeAndOrder")
    public void saveEmployeeAndOrder(){

        orderInfoService.saveOrderAndEmployee();
    }
}
